function $e(ele) {
	return document.getElementById(ele);
}
function html_escape(str) {
    return String(str).replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// zebra table
function fix_tables() { $("table").attr("cellspacing","0").attr("cellpadding","0"); }
function zebra() {
	// Table fixes
	$("table.zebra").each(function(){table_zebra($(this));});
	$("ul.zebra").each(function(){ul_zebra($(this));});
}
function table_zebra($table)
{
	fix_tables();
	$table.find("tr:nth-child(even)").addClass("odd"); // godt lavet
	$table.find("tr:nth-child(odd)").removeClass("odd"); // godt lavet
}
// zebra List
function ul_zebra($ul)
{
	$ul.find("li:nth-child(even)").addClass("odd"); // godt lavet
	$ul.find("li:nth-child(odd)").removeClass("odd"); // godt lavet
}
function make_highlighted_rows()
{
	$(".highlighted_row").each(function(){
		$tr = $(this);
		$tr.siblings("tr").each(function(){
			if($tr != $(this))
			{
				$(this).children(":first").addClass("highlight_td_left_std");
				$(this).children(":last").addClass("highlight_td_right_std");
			}
		});
		$tr.children().addClass("highlight_td");
		$tr.children(":first").addClass("highlight_td_left");
		$tr.children(":last").addClass("highlight_td_right");

		$tr.removeClass("highlighted_row").addClass("highlighted_row_done");
	});
}
function get_loading_img(size)
{
	var img;
	if(size == "big") img = '<img class="loading" src="/pics/big_loading.gif" alt="loading..." title="loading..." />';
	else if(size == "hori") img = '<img class="loading" src="/pics/five_horizontal_loading.gif" alt="loading..." title="loading..." />';
	else img = '<img class="loading" src="/pics/small_circular_loading.gif" alt="loading..." title="loading..." />';
	return img;
}
function number_format(number)
{
	number += '';
	x = number.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
/* preload */
function preload(img_url) {
	$("body").append(
		$("<img src='"+img_url+"' class='hidden'>").hide()
	)
}

// ** Captcha ** //
function captcha_post(type,ids,callback)
{
	ids = ids || [];
	var vars = {};
	for(var i=0;i<ids.length;i++)
	{
		vars[ids[i]] = $("#"+ids[i]).val();
	}
	$.post("/ajax/captcha_post.php", {"cap":$("#captcha_input").val(),"type":type,"vars":vars}, callback, "json");
	return false;
 }
function change_captcha()
{
	$('#captcha_image').attr("src","/ajax/captcha_image.php?rnd=" + Math.random());
}
// ** Page content replace **//
function pc_replace(pagecontent,ar)
{
	// Takes pagecontent string, and array of { "[CLUB]" : "AC Packers" }
	var pc = pagecontent;
	for(var i in ar)
	{
		pc = pc.replace(""+i,""+ar[i]);
	}
	return pc;
}
/* Emboss */
function emboss() {
	$(".emboss").each(function() {
		var outer_class = $(this).attr("wrap_class");
		$(this)
			.removeClass("emboss")
			.addClass("embossed")
			.wrap(
				$("<div class='emboss_outer'>").addClass(outer_class)
			);
	});
}

function page_refresh()
{
	window.location.reload();
}
function body_refresh()
{
	$(window).unbind();
	$("body").click(function(){page_refresh()});
}
function submit_form(id)
{
	$("#"+id).submit();
}
/*
function pro_update()
{
	$.post("/ajax/pro_update.ajax.php",{},function(data){
		if(data != null)
		{
			$("#buddy_list_pro").find(".pro_days").text(data["days"]);
		}
	},"json");
}
*/
// ** Function for show Youth Megastars! ** //
function show_youth_rec(rec,potential) {
	str = "";
	for(i = 0; i < 5;i++) {
		rec = rec < 0 ? 0 : rec;
		potential = potential < 0 ? 0 : potential;

		if(rec == 0) {
			if(potential == 0) {
				str += '<span class="megastar empty"></span>';
			} else if(potential == 0.5)	{
				str += '<span class="megastar potential_half"></span>';
			} else {
				str += '<span class="megastar potential"></span>';
			}
		} else if(rec == 0.5) {
			if(potential == 0 || potential == 0.5) {
				str += '<span class="megastar recomendation_half"></span>';
			} else {
				str += '<span class="megastar recomendation_potential"></span>';
			}
		} else {
			str += '<span class="megastar recomendation"></span>';
		}

		rec--;
		potential--;

	}
	return str;
}
function online_indicator(online)
{
	if(online) return "<img src='/pics/icons/online.gif' tooltip='Online' />";
	else return "<img src='/pics/icons/offline.gif' tooltip='Offline' />";
}
function make_text_fade($obj,type)
{
	if(type == "forum")
	{
		var img = $obj.parent().hasClass("hover") ? "forum/hover_background_fade.png" : "forum/background_fade.png";
		$obj.parent()
		.mouseover(function(){
			$obj.find(".text_fade_overlay").css("background","url(/pics/forum/hover_background_fade.png)").addClass("hover");
		})
		.mouseout(function(){
			$obj.find(".text_fade_overlay").css("background","url(/pics/forum/background_fade.png)").removeClass("hover");
		});
	}
	else
	{
		var img = $obj.hasClass("message_unread") || $obj.parent().hasClass("message_unread") || $obj.hasClass("odd") || $obj.parent().hasClass("odd")  ? "green_fade_right_light.png" : "green_fade_right.png";
	}
	if($obj.css("position") == "" || $obj.css("position") == "static") $obj.css("position","relative");
//	var pos = $obj.position();
	var border = parseInt($obj.css("border-top-width"));
	var innerHeight = $obj.innerHeight();
	var $div = $("<div />").addClass("text_fade_overlay").css({
		"position":"absolute",
//		"z-index":"2",
//		"left":(pos.left-23+$obj.width()+parseInt($obj.css("padding-left")))+"px",
//		"top":($obj.position().top+border)+"px",
		"margin-left":($obj.width()-23+parseInt($obj.css("padding-left")))+"px",
//		"top":(border)+"px",
		"height":innerHeight-2+"px",
		"width":"23px",
		"background":"url(/pics/"+img+") repeat-y top right"
	}).prependTo($obj);
}
function get_player_link(ar)
{
	ar["class"] = ar["class"] || "";
	var player = ar["player"];
	var auto_tooltip = ar["auto_tooltip"] ? "player_link='"+player["id"]+"'" : "";
	var tooltip = ar["tooltip"] ? "tooltip='"+ar["tooltip"]+"'" : "";
	var url = "/players/"+player["id"]+"/"+player["name"].replace(". ","_").replace(" ","_")+"/";
	if(ar["only_url"]) return url;
	return "<a href='"+url+"'"+auto_tooltip+"class='"+ar["class"]+"'>"+player["name"]+"</a>";
}
function get_club_link(ar)
{
	ar["class"] = ar["class"] || "";
	var club = ar["club"];
//	var auto_tooltip = ar["auto_tooltip"] ? "player_link='"+player["id"]+"'" : "";
	var tooltip = ar["tooltip"] ? "tooltip='"+ar["tooltip"]+"'" : "";
	var flag = ar["flag"] && club["country"] != "" ? " "+get_flag(club["country"]) : "";
	var url = "/club/"+club["id"]+"/";
	if(ar["only_url"]) return url;
	return "<a href='"+url+"'"+"class='"+ar["class"]+"'>"+club["name"]+flag+"</a>";
}
function get_flag(country)
{
	if (country == "") return "";
	return "<img src=\"/pics/flags/gradient/"+country+".png\" />";
}
var rec_format = function(text){
	var rec = parseInt(text);
	//array of find replaces
/*			var findreps = [

	];
	for(var i in findreps){
		newText = newText.replace(findreps[i].find, findreps[i].rep);
	} */

	if (rec>20) return number_format(rec/2);

	var str = "";
	for(var i = 0 ; i < 5; i++)
	{
		if(rec > 1) str += "<img src=\"/pics/star.png\" class='rec_star'/>";
		else if(rec > 0) str += "<img src=\"/pics/half_star.png\" class='rec_star'/>";
		else str += "<img src=\"/pics/dark_star.png\" class='rec_star' />";
		rec -= 2;
	}
	return str;
};

function color_favposition(pos,ignore_side,no_wrapper,only_one_side)
{
	ignore_side = ignore_side || false;
	pos = pos || "";
	var str = "";
	var side = ["",""];
	pos = pos.toLowerCase();
	// Substitute
	if(pos.indexOf("sub") != -1) return "<span class=\"favposition short\"><span class=\"sub\">"+global_content["substitute_abbr"]+"</span></span>";
	// More than one position
	var pos2 = pos.split("/");
	if(pos2[1]) return "<span class=\"favposition short\">"+color_favposition(pos2[0],false,true)+"/"+color_favposition(pos2[1],false,true)+"</span";
	var pos2 = pos.split(", ");
	if(pos2[1]) return "<span class=\"favposition short\">"+color_favposition(pos2[0],false,true)+", "+color_favposition(pos2[1],false,true)+"</span";

	// Only one position
	if(pos == "gk")
	{
		side = pos.split("gk");
		str = "<span class=\"gk\">"+global_content["gk_xxx"]+"</span>";
	}
	else if(pos.indexOf("dm") != -1)
	{
		side = pos.split("dm");
		str = "<span class=\"m\">"+global_content["dm_xxx"]+"</span>";
	}
	else if(pos.indexOf("d") != -1)
	{
		side = pos.split("d");
		str = "<span class=\"d\">"+global_content["d_xxx"]+"</span>";
	}
	else if(pos.indexOf("om") != -1)
	{
		side = pos.split("om");
		str = "<span class=\"om\">"+global_content["om_xxx"]+"</span>";
	}
	else if(pos.indexOf("m") != -1)
	{
		side = pos.split("m");
		str = "<span class=\"m\">"+global_content["m_xxx"]+"</span>";
	}
	else if(pos.indexOf("f") != -1)
	{
		side = pos.split("f");
		str = "<span class=\"f\">"+global_content["f_xxx"]+"</span>";
	}
	else return "";
	if(pos.indexOf("f") != -1) side = "";
	else if(only_one_side && side[1].indexOf("c") != -1) side = "c"; // C not split into CL,C,CR but input like that
	else side = side[1];
	side = side.replace("l",global_content["left_abbr"]).replace("r",global_content["right_abbr"]).replace("c",global_content["center_abbr"]);
	var side_html = ignore_side || side=="" ? "" : " "+"<span class=\"side\">"+side+"</span>";
	if(no_wrapper) return str+side_html;
	return "<span class=\"favposition short\">"+str+side_html+"</span>";
}
/* Money */
function money(cash) {
	cash = cash || "";
	cash = cash+"";
	cash = cash.replace(/\./g,"").replace(/,/g,"");
	return "<span class='coin'>"+number_format(cash)+"</span>";
}
function money_big(cash) {
	cash = cash || "";
	cash = cash+"";
	cash = cash.replace(/\./g,"").replace(/,/g,"");
	return "<span class='coin_big'>"+number_format(cash)+"</span>";
}
function slide_toggle(id,update)
{
	$("#"+id).slideToggle(200);
	$("#"+id+"_arrow").toggleClass("slide_toggle_closed");
	$("#"+id+"_arrow").toggleClass("slide_toggle_open");
	$("#"+id).removeClass("display_none");
	if(update)
	{
		var bool = $("#"+id+"_arrow").hasClass("slide_toggle_open") ? 1 : 0;
		update_settings(id,bool);
	}
}
// Suggestion box global vars
var suggest_clubs_current = "";
var suggest_clubs_blur = true;

// ** Get suggestions ** //
// ****************** //
function suggest_clubs(limit,suggest_input_id)
{
	// Set standard attrs
	suggest_input_id = suggest_input_id || "suggest_clubs";
	limit = limit || 10;

	if($("#"+suggest_input_id).is(":hidden")) return false;
	// Disable autocomplete
	$("#"+suggest_input_id).attr("autocomplete","off");
	// Enabled keydown-function on first type-in
	if($("#"+suggest_input_id).attr("keydown_set") != "true"){
		suggest_clubs_set_keydown(limit,suggest_input_id);
		$("#"+suggest_input_id).attr("keydown_set","true")
	}
	// Enable box remove on blur
	$("#"+suggest_input_id).blur(function(){
		if(suggest_clubs_blur)
		{
			suggest_clubs_clear(suggest_input_id);
		}
	});

	// Get search query
	var q_str = $("#"+suggest_input_id).val();
	if(q_str != "" && q_str != suggest_clubs_current)
	{
		suggest_clubs_current = q_str;
		// Get suggestion box
		$suggest = $("#suggest_clubs_box");
		if($suggest.length == 0){
			var $suggest = $("<div id='suggest_clubs_box'/>").appendTo("body").hide();
		}
		var $pos = $("#"+suggest_input_id).offset();
		$suggest.css({
			"border-radius":"0px 0px 4px 4px",
			"border":"1px solid #41631F",
//			"border-top": "none",
			"background":"#578229",
			"position": "absolute",
			"min-width":"200px",
			"z-index": "100",
			"top": ($pos.top + $("#"+suggest_input_id).outerHeight())+"px",
			"left": ($pos.left)+"px"
		});
		$suggest.html(get_loading_img()).slideDown();
		var settings = "{}";
		if($("#"+suggest_input_id+"_settings").length > 0)
		{
			settings = $("#"+suggest_input_id+"_settings").val();
		}
		// Do ajax
		$.post("/ajax/suggest_clubs.ajax.php",{"q_string":q_str,"limit":limit,"settings":settings},function(data){
			if(data != null)
			{
				// Set selected suggestion to none
				$("#"+suggest_input_id).attr("suggestion_id",0);

				//Get href
				var club_href = $("#"+suggest_input_id+"_href").val() == "" ? "/club/" : $("#"+suggest_input_id+"_href").val();

				$suggest.html("");

				// Get input position and place suggestion box

//				$("body").append($suggest);

				if(data[0] == undefined)
				{ // Nothing found (obviously)
					$suggest.html("<div class='align_center'>* Nothing found *</div>");
				}
				else {
					var j = 1;
					// Loop data and put them in suggestion box
					for(var i in data)
					{
						var clubnick = data[i]["clubnick"] == "" ? "" : " ("+data[i]["clubnick"]+")";
						var country = get_flag(data[i]["country"])+' '+data[i]["division"]+'.'+data[i]["group"];
						var $suggestion = $("<div class='suggestion' />");
						$suggestion.css({
							"cursor":"pointer",
							"padding":"2px 3px 2px 3px"
						});
						$suggestion.append(data[i]["clubname"]+clubnick+' '+country);

						// Set attributes for selection (counter and club_id)
						$suggestion.attr("i",j);
						$suggestion.attr("club_id",data[i]["id"]);
						$suggestion.attr("country",data[i]["country"]);
						$suggestion.attr("id","suggestion_id_"+j);
						//Set hover and click functions
						$suggestion.mouseover(function(){
							suggest_clubs_blur = false;
							$(".suggestion").css({"background":"transparent","white-space":"nowrap"});
							$(this).css("background","#6C9922");
							$("#"+suggest_input_id).attr("suggestion_id",$(this).attr("i"));
						}).mouseout(function(){
							suggest_clubs_blur = true;
							$(this).css("background","transparent");
						});
						$suggestion.click(function(){
							suggest_clubs_select(club_href,$(this));
						});
						// append to box
						$suggest.append($suggestion);
						j++;
					}
				}
				// Place box
				var box_top = ($pos.top +$("#"+suggest_input_id).outerHeight());
				var box_left = $pos.left;
				box_top = box_top + $suggest.outerHeight(true) > $(window).height()  ? $pos.top - $suggest.outerHeight(true) : box_top;
				box_top = box_top < 0 ? ($pos.top +$("#"+suggest_input_id).outerHeight()) : box_top;
				box_left = box_left + $suggest.outerWidth(true) > $(window).width() ? $(window).width() - $suggest.outerWidth(true): box_left;
				$suggest.css({
					"top": box_top+ "px",
					"left":  box_left+"px"
				});
			} //data != null
		},"json");
	}
	else if(q_str == "")
	{
		// Clear box, if search query is empty
		suggest_clubs_clear(suggest_input_id);
	}
}

// Clear suggestion box
function suggest_clubs_clear(suggest_input_id){
	suggest_clubs_current = "";
	$("#suggest_clubs_box").remove();
	$("#"+suggest_input_id).attr("suggestion_id",0);
}

// Excecute select suggestion (go to url/run js)
function suggest_clubs_select(club_href,$suggestion){
	club_href = club_href || "/club/";
	if(club_href.indexOf("javascript:") != -1){
		var func = club_href.split("javascript:");
		var eval_str = func[1]+"('"+$suggestion.attr("club_id")+"','"+$suggestion.attr("i")+"')";
		try	{
			eval(eval_str);
		}
		catch(err){
			//			return false;
		}
	}
	else{
		var locat = "";
		if(club_href.indexOf("XYZ") != -1)
		{
			 locat =  club_href.replace("XYZ",$suggestion.attr("club_id"));
		}
		else
		{
			locat =  club_href+$suggestion.attr("club_id");
		}
		window.location = locat;
	}
}

// Set keyboard functions for selections
function suggest_clubs_set_keydown(limit,suggest_input_id){
	suggest_input_id = suggest_input_id || "suggest_clubs";
	var club_href = $("#"+suggest_input_id+"_href").val() == "" ? "/club/" : $("#"+suggest_input_id+"_href").val();
	$("#"+suggest_input_id).keydown(function(event){
		if(event.keyCode == 40)
		{  // Arrow down
			var new_id = parseInt($(this).attr("suggestion_id"))+1;
			if($("#suggestion_id_"+new_id).length > 0)
			{
				$("#suggestion_id_"+$(this).attr("suggestion_id")).css("background","transparent");
				$(this).attr("suggestion_id",new_id);
				$(".suggestion").css("background","transparent");
				$("#suggestion_id_"+new_id).css("background","#6C9922");
			}
			else if(new_id == 1){
				suggest_clubs_clear(suggest_input_id);
				suggest_clubs(limit,suggest_input_id);
			}
			return false;
		}
		else if(event.keyCode == 38)
		{ // Arrow up
			var new_id = parseInt($(this).attr("suggestion_id"))-1;
			var size = $("#"+suggest_input_id).length;
			if($("#suggestion_id_"+new_id).length > 0)
			{
				$("#suggestion_id_"+$(this).attr("suggestion_id")).css("background","transparent");
				$(this).attr("suggestion_id",new_id);
				$("#suggestion_id_"+new_id).css("background","#6C9922");
			}
			return false;
		}
		else if(event.keyCode == 13 || event.keyCode == 9)
		{// Enter OR Tab
			if($("#suggestion_id_"+$("#"+suggest_input_id).attr("suggestion_id")).length != 0)
			{
				suggest_clubs_select(club_href,$("#suggestion_id_"+$("#"+suggest_input_id).attr("suggestion_id")));
			}
			if(event.keyCode == 13)
			{ // tab possible without selecting club
				return false;
			}
		}
		else if(event.keyCode == 27)
		{ // Escape
			suggest_clubs_clear(suggest_input_id);
			suggest_clubs_current = $("#"+suggest_input_id).val();
			return false;
		}
		else{
			//			console.log(event.keyCode);
		}
	});
}
function remove_short_list_player(player_id,callback)
{
//	create_message_box();
//	$("#msg").html("<div class='std align_center'>"+get_loading_img()+"</div>");
//	show_message_box();

	if(typeof callback != "function")
	{
		modal.html(get_loading_img()).show();
	}
	$.post("/ajax/players_shortlist.ajax.php",{"type":"remove","player_id":player_id},function(data){
		if(data != null)
		{
			if(typeof callback == "function")
			{
				callback.call(this,player_id);
				return false;
			}
			var $html = $("<div class='std'>");
			$html.append("<h2>"+pagecontent["remove_shortlist_1"]+"</h2><p>"+pagecontent["remove_shortlist_2"]+"</p>");
			$html.append("<div class='msgbuttons'>"+make_button(global_content["ok"],"javascript:page_refresh()","")+"</div>");
			body_refresh();
//			$("#msg").html($html);
//			add_close_button();
			modal.html($html).show();
		}
	},"json");
}
// Tut vars
var tutorial_youth_report,tutorial_youth_hire,this_is_tutorial,tutorial_facility_upgrade,tutorial_transfer_player,tutorial_transferbid_made;
// ** Transfer List Player Boxes ** //
function pop_transferlist_player(player_id,bid_id,player_name,bid_value)
{
	var loading = "<div class='std align_center'>"+get_loading_img()+"</div>";
	button_disable($("#transfer_submit_button"));
	modal.html(loading).show();
	$.post("/ajax/transferlist_player.ajax.php",{"type":"get","player_id":player_id,"bid_id":bid_id},function(data){
		if(data != null)
		{
			player_name = data["player_name"];
			var $html = $("<div class='std'>").addClass("transferlist_player_div");
			if(data["error"] != "")
			{
				$html.html("<span class='large'>"+data["error"]+"</span><div style='padding-top:10px' class='align_center'><span onclick='javascript:modal.hide()' class='button'><span class='button_border'>"+global_content["ok"]+"</span></span></div>");
			}
			else
			{  // <img src='/pics/profile_mockup.png' class='float_right' style='margin: 10px 20px 5px 5px;'>
				$html.append($("<div />").addClass("float_right").html(data["player_image"]));
				$html.append("<h2>"+pagecontent[9]+"</h2>");
				$html.append("<div class='very_large bold' style='margin-bottom:5px;'>"+player_name+"</div>");
				var $form = $("<form>").append($("<input type='hidden' id='player_name' />").val(player_name)).appendTo($html);
				if(this_is_tutorial)
				{ // For tutorial only show
					$form.append("<p>"+pagecontent[102]+"</p>");
					$form.append("<input type='hidden' id='min_price' name='min_price' style='width:250px' class='emboss' value='"+data["min_price_string"]+"' /><input type='hidden' id='max_price' name='max_price' value='"+data["max_price"]+"' />");
				}
				else
				{
					if(data["bid"] > 0)
					{
						$form.append(pc_replace(pagecontent[10],{"[AMOUNT]":"<strong>"+bid_value+"</strong>","[PLAYER_NAME]":"<span class='very_large'><strong>"+player_name+"</strong></span>"}));
						$form.append("<input type='hidden' id='bid_id' value='"+bid_id+"' /><input type='hidden' id='min_price' name='min_price' style='width:250px' class='emboss' value='"+bid_value+"' />");
					}
					else
					{
						$form.append("<p>"+pagecontent[103]+"</p><h3>"+pagecontent[104]+"</h3><div>"+pc_replace(pagecontent[105],{"[player]":"<strong>"+player_name+"</strong>","[max_price]":"<strong>"+data["max_price_string"]+"</strong>"})+"</div><br /><label for='min_price'>"+pagecontent[11]+" </label><input type='text' id='min_price' name='min_price' style='width:250px' class='emboss' value='"+data["min_price_string"]+"' /><input type='hidden' id='max_price' name='max_price' value='"+data["max_price"]+"' />");
					}
					var select_time = "<select id='exp_time1'>"
					for(var i=0;i<24;i++)
					{
						var t = zeros(i,2)+":"+data["expiry_min"];
						var sel = zeros(i,2) == data["expiry_hour"] ? " selected":"";
						select_time += "<option value='"+t+"'"+sel+">"+t+"</option>";
					}
					select_time +="</select>";
					var select_time2 = "<select id='exp_time2'>"
					for(var i=0;i<24;i++)
					{
						var t = zeros(i,2)+":"+data["expiry_min"];
						var sel = zeros(i,2) == data["expiry_hour"] ? " selected":"";
						select_time2 += "<option value='"+t+"'"+sel+">"+t+"</option>";
					}
					select_time2 +="</select>";
					var select_days = "<select id='exp_days'>"
					for(var i=2;i<10;i++)
					{
						var sel = i == 5 ? " selected":"";
						select_days += "<option value='"+i+"'"+sel+">"+i+"</option>";
					}
					select_days +="</select>";
					$form.append("<h3>"+pagecontent[12]+"</h3>");
					var $radios = $("<div />").appendTo($form);
					$radios.append("<input tabindex='1' class='less_space' type='radio' name='transfer_expiry' exp_type='1' id='transfer_expiry1' value='1' checked onchange='transfer_pimp_disable(this)'/><label for='transfer_expiry1'>"+data["pimp_exp1"]+" "+data["pimp_tmtime"]+"</label>");
					$radios.append("<input tabindex='2' class='less_space' type='radio' name='transfer_expiry' exp_type='2' id='transfer_expiry2' value='1' "+data["pimp_exp2_disabled"]+" onchange='transfer_pimp_disable(this)'/><label for='transfer_expiry2'>"+data["pimp_exp2_1"]+" "+select_time+" "+data["pimp_tmtime"]+" <strong>"+data["pimp_exp2_2"]+"</strong></label>");
					$radios.append("<input tabindex='3' class='less_space' type='radio' name='transfer_expiry' exp_type='3' id='transfer_expiry3' value='1' "+data["pimp_exp3_disabled"]+" onchange='transfer_pimp_disable(this)'/><label for='transfer_expiry3'>"+data["pimp_exp3_1"]+" "+select_days+" "+data["pimp_exp3_2"]+" "+select_time2+" "+data["pimp_tmtime"]+" <strong>"+data["pimp_exp3_3"]+"</strong></label>");

					$radios.append("<div class='clear'></div>");
					$radios.append("<h3>"+pagecontent[13]+"</h3>");
					$radios.append("<input tabindex='4' class='less_space' type='radio' name='transfer_pimp' pimp_type='1' id='transfer_pimp1' value='1' checked /><label for='transfer_pimp1'>"+data["pimp_text1"]+"</label>");
					$radios.append("<input tabindex='5' class='less_space' type='radio' name='transfer_pimp' pimp_type='2' id='transfer_pimp2' value='1' "+data["pimp_text2_disabled"]+"/><label for='transfer_pimp2'>"+data["pimp_text2"]+"</label>");
					$radios.append("<input tabindex='6' class='less_space' type='radio' name='transfer_pimp' pimp_type='3' id='transfer_pimp3' value='1' "+data["pimp_text3_disabled"]+"/><label for='transfer_pimp3'>"+data["pimp_text3"]+"</label>");
					$radios.append("<input type='checkbox' tabindex='7' name='transfer_text' id='transfer_text' "+data["pimp_textarea_disabled"]+"/><label for='transfer_text'>"+data["pimp_textarea_1"]+" <span id='chars_left'>255</span> "+data["pimp_textarea_2"]+"</label><div class='clear'></div><input type='text' tabindex='8' name='transfer_textarea' id='transfer_textarea' class='stdwidth emboss' "+data["pimp_textarea_disabled"]+" onkeyup='chars_left(\"chars_left\",255,\"transfer_textarea\")' onfocus='transfer_text_focus(\"focus\");' onblur='transfer_text_focus(\"blur\");' />");
					$radios.append("<div class='clear'></div>");
					}
				$html.append("<div style='padding-top:10px' class='align_center'><span onclick='submit_transferlist_player("+player_id+")' class='button big_button large button_icon primary_button' tabindex='9'  id='transfer_submit_button'><span class='button_border'>"+global_content["sell"]+"</span></span> <span onclick='javascript:modal.hide()' class='button' tabindex='10' ><span class='button_border'>"+global_content["cancel"]+"</span></span></div>");
			}
			modal.transition($html,function(){
				make_radio("transfer_expiry1");
				make_radio("transfer_pimp1");
				make_checkbox("transfer_text");
				emboss();
				$("#exp_days").selectmenu({
					"style":"dropdown",
					"maxHeight":"200",
					"width": "55"
				}).selectmenu("disable");
				$("#exp_time1").selectmenu({
					"style":"dropdown",
					"maxHeight":"200",
					"width": "80"
				}).selectmenu("disable");
				$("#exp_time2").selectmenu({
					"style":"dropdown",
					"maxHeight":"200",
					"width": "80"
				}).selectmenu("disable");
			});
		}
	},"json");
}
function  transfer_pimp_disable(el)
{
	if($(el).is(":checked"))
	{
		$("#exp_days").selectmenu("disable");
		$("#exp_time1").selectmenu("disable");
		$("#exp_time2").selectmenu("disable");
		 $("label[for="+$(el).attr("id")+"]").find("select").each(function(){
			var id = $(this).attr("id");
			$("#"+id).selectmenu("enable");
		 });
	}
}
function transfer_text_focus(type)
{
	if(type=="focus" && !$("#transfer_text").is(":checked")) $("#transfer_text_checkbox").click();
	if(type=="blur" && $("#transfer_text").is(":checked") && $("#transfer_textarea").val() == "") $("#transfer_text_checkbox").click();
}
function submit_transferlist_player(player_id)
{
	var $pimp = $("[name=transfer_pimp]:checked");
	var $exp = $("[name=transfer_expiry]:checked");
	var min_price = $("#min_price").val();
	var max_price = $("#max_price").val();
	min_price = min_price.replace(/,/g, "");
	min_price = min_price.replace(/\./g, "");
	if(parseInt(min_price) > parseInt(max_price))
	{
		$("#min_price").closest(".emboss_outer").after("<p class='error'>"+pagecontent[106]+"</p>");
		$("#min_price").focus();
		return false;
	}
	button_disable($("#transfer_submit_button"));
	var exp_time = "", exp_days= "";
	if($exp.attr("exp_type") == 2)
	{
		exp_time = $("#exp_time1").val();
	}
	else if($exp.attr("exp_type") == 3)
	{
		exp_time = $("#exp_time2").val();
		exp_days = $("#exp_days").val();
	}
	var text = "";
	if($("#transfer_text").is(":checked") && $("#transfer_textarea").val() != "") text = $("#transfer_textarea").val();
//	/*
	$.post("/ajax/transferlist_player.ajax.php",{"type":"list","player_id":player_id,"text":text,"pimp":$pimp.attr("pimp_type"),"expiry_time" : exp_time,"expiry_days": exp_days, "bid_id":$("#bid_id").val(),"min_price":min_price},function(data){
		if(data != null)
		{
			if(typeof tutorial_transfer_player == "function")
			{
				tutorial_transfer_player();
			}
			var $html = $("<div class='std'>");
			var player_name = $("#player_name").val();
			if(data["error"] == "")
			{
				$html.append("<p class='large'><strong>"+player_name+"</strong> "+data["text"]+"</span>");
			}
			else
			{
				 $html.html(data["error"]);
			}
			$html.append("<div class='align_center' style='padding-top: 10px'><a href='javascript:page_refresh()' class='button'><span class='button_border'>"+global_content["ok"]+"</span></a></div>");
			modal.transition($html,function(){
				modal.banner();
			});
			body_refresh();
		}
	},"json");
// */
}
function update_transfer_radio(el)
{
	$("[name=transfer_method]:checked").val($(el).val());
}
function post_transfer_bid(player_id)
{
	var $transfer = $("[name=transfer_method]:checked");
	var bid = $transfer.val();
	var min_bid = $("#min_bid").val();
	var player_name = $("#bid_player_name").val();
	if(parseInt(bid.replace(/,/g, "").replace(/\./g, "")) < parseInt(min_bid.replace(/,/g, "").replace(/\./g, "")))
	{
		//error
		var $error = $("#transfer_method").siblings(".error");
		if($error.length == 0) $error = $("<p class='error' />").insertAfter("#transfer_method");
		$error.html("Minimum bid not met");
		return false;
	}
	button_disable($("#bid_button"));
	$("#transfer_method").siblings(".error").remove();
	var $html = $("<div />");
	modal.transition(get_loading_img(),function(){
		$.post("/ajax/transfer_bids.ajax.php",{"type":"transfer_bid","player_id":player_id,"transfer_type":$transfer.attr("transfer"),"bid":bid,"session_id":SESSION["id"]},function(data){
			if(data != null)
			{
				$html.html("<h2>"+global_content["make_bid"]+"</h2>");
				if(data["error"] != "")
				{
					$html.append("<p class='error'>"+data["error"]+"</p>");
				}
				else
				{
					// Tutorial
					if(typeof tutorial_transferbid_made == "function") tutorial_transferbid_made();

					$html.append("<p>"+data["succes"]+"</p>");
					if(data["agent"] !="")
					{
						$html.append("<p>"+data["agent"]+"</p>");
					}
				}
				if(!this_is_tutorial) $html.append("<p>"+get_player_link({"player":{"id":player_id,"name":player_name}})+"</p>");
				$html.append("<div class='msgbuttons'>"+make_button(global_content["ok"],"javascript:page_refresh()","")+"</div>");
				modal.html($html).banner();
				body_refresh();
			}
		},"json");
	});
}
function pop_withdraw_bid(bid_id,player,bid,player_name)
{
	var player_name = player_name || $("#player_"+player).attr("player_name");
	modal.html("<div class='std'><form method='post' action='' id='withdraw_bid_form'><input type='hidden' name='withdraw_bid_id' value='"+bid_id+"' /><input type='hidden' name='player_name' value='"+player_name+"' /></form> <h2>"+pagecontent[3]+"</h2> "+pc_replace(pagecontent[4],{"[BID_AMOUNT]":"<strong>"+bid+"</strong>","[PLAYER_NAME]":"<strong>"+player_name+"</strong>"})+" <div style='padding-top:10px' class='align_center'><a href='javascript:transfer_bid(\"withdraw_bid\")' class='button'><span class='button_border'>"+global_content["withdraw"]+"</span></a> <span onclick='javascript:modal.hide()' class='button'><span class='button_border'>"+global_content["cancel"]+"</span></span></div></div>").show();
}
function pop_reject_bid(bid_id,player,bid,bidder_id,b_team)
{
	var bid_value = bid || "";
	bid_value = bid_value.replace(/,/g, "").replace(/\./g, "");
	var html = "<div class='std'><h2>"+pagecontent[5]+"</h2>"+pc_replace(pagecontent[6],{"[BID_AMOUNT]":bid,"[PLAYER_NAME]":$("#player_"+player).attr("player_name")})+"<br /><form method='post' action='' id='reject_bid_form'><input type='hidden' name='reject_bid' value='"+bid_id+"' /><input type='hidden' name='player_id' value='"+player+"' /><input type='hidden' name='player_name' value='"+$("#player_"+player).attr("player_name")+"' /><input type='hidden' name='bidder_id' value='"+bidder_id+"' /><input type='hidden' value='"+bid_value+"' name='bid_value'><input type='hidden' name='b_team' value='"+b_team+"' /><label for='comment'>"+global_content[496]+"</label><textarea class='emboss' name='comment' id='comment' rows='3' cols='70' ></textarea></form><div style='padding-top:10px' class='align_center'><span onclick='javascript:transfer_bid(\"reject_bid\")' class='button'><span class='button_border'>"+global_content["reject"]+"</span></span> <span onclick='javascript:modal.hide()' class='button'><span class='button_border'>"+global_content["cancel"]+"</span></span></div></div>";
	modal.html(html).show();
	emboss();
}
function pop_accept_bid(bid_id,player,bid,bidder_id,b_team)
{
	var html = "<div class='std'><h2>"+pagecontent[7]+"</h2>"+pc_replace(pagecontent[8],{"[BID_AMOUNT]":bid,"[PLAYER_NAME]":$("#player_"+player).attr("player_name")})+"<br /><form method='post' action='' id='accept_bid_form'><input type='hidden' name='accept_bid' value='"+bid_id+"' /><input type='hidden' name='player_id' value='"+player+"' /><input type='hidden' name='player_name' value='"+$("#player_"+player).attr("player_name")+"' /><input type='hidden' name='bidder_id' value='"+bidder_id+"' /><input type='hidden' name='b_team' value='"+b_team+"' /></form><div style='padding-top:10px' class='align_center'><span onclick='javascript:pop_transferlist_player("+player+","+bid_id+",\""+$("#player_"+player).attr("player_name").replace("'","-").replace("&#39;","-")+"\",\""+bid+"\")' class='button' id='transfer_submit_button'><span class='button_border'>"+global_content["next"]+"</span></span> <span onclick='javascript:modal.hide()' class='button'><span class='button_border'>"+global_content["cancel"]+"</span></span></div></div>";
	modal.html(html).show();
	emboss();
}

function pop_delete_agent(agent_id,player_name)
{

	modal.html("<div class='std'><h2>"+pagecontent[16]+"</h2>"+pc_replace(global_content[495],{"[player]":player_name})+"<form method='post' action='' id='delete_agent'><input id='agent_id' type='hidden' name='agent_id' value='"+agent_id+"' /><input type='hidden' name='player_name' value='"+player_name+"' /></form><div style='padding-top:10px' class='align_center'><span onclick='javascript:transfer_bid(\"delete_agent\")' class='button' tabindex='1' ><span class='button_border'>"+global_content["delete"]+"</span></span> <span onclick='javascript:modal.hide()' class='button' tabindex='2' ><span class='button_border'>"+global_content["cancel"]+"</span></span></div></div>").show();
}
function transfer_bid(type)
{
	var $html = $("<div/>");
	var arr = {};
	var succes_text = "";
	var error_text = "";
	var header = $("#modal h2");
	if(type=="delete_agent")
	{
		arr["agent_id"] = $("#agent_id").val();
		arr["player_name"] = $("#delete_agent [name=player_name]").val();
		error_text = "Too Late!";
//		succes_text = "Agent on "+arr["player_name"]+" deleted."; // 494
		succes_text = pc_replace(global_content[494],{"[player]":arr["player_name"]});
	}
	else if(type=="reject_bid")
	{
		arr["reject_bid"] = $("#reject_bid_form [name=reject_bid]").val();
		arr["bid_value"] = $("#reject_bid_form [name=bid_value]").val();
		arr["player_id"] = $("#reject_bid_form [name=player_id]").val();
		arr["player_name"] = $("#reject_bid_form [name=player_name]").val();
		arr["bidder_id"] = $("#reject_bid_form [name=bidder_id]").val();
		arr["b_team"] = $("#reject_bid_form [name=b_team]").val();
		arr["comment"] = $("#reject_bid_form [name=comment]").val();
//		succes_text = "Bid on "+arr["player_name"]+" rejected."; //492
		succes_text = pc_replace(global_content[492],{"[player]":arr["player_name"]});
	}
	else if(type=="withdraw_bid")
	{
		arr["withdraw_bid_id"] = $("#withdraw_bid_form [name=withdraw_bid_id]").val();
		arr["player_name"] = $("#withdraw_bid_form [name=player_name]").val();
//		succes_text = "Bid on "+arr["player_name"]+" withdrawn."; // 493
		succes_text = pc_replace(global_content[493],{"[player]":arr["player_name"]});
	}
	else
	{
		return false;
	}
	modal.html(get_loading_img());
	$.post("/ajax/transfer_bids.ajax.php",{"type":type,"value":arr},function(data)
	{
		if(data != null)
		{
			if (data["error"]==1)
			{
				$html.html(header).append(error_text).append("<div class='align_center' style='padding-top:10px'>"+make_button(global_content["ok"],"javascript:page_refresh()","")+"</div>");
			}
			else
			{
				$html.html(header).append(succes_text).append("<div class='align_center' style='padding-top:10px'>"+make_button(global_content["ok"],"javascript:page_refresh()","")+"</div>");
			}
			modal.transition($html).banner();
			body_refresh();
		}
	},"json");
}

function short_list_player(player_id,in_transferlist)
{
	in_transferlist = in_transferlist || false;
	modal.html(get_loading_img()).show();
	$.post("/ajax/players_shortlist.ajax.php",{"player_id":player_id},function(data){
		if(data != null)
		{
			var $html = $("<div>");
			$html.append("<h2>"+global_content[474]+"</h2><p>"+global_content[475]+"</p>");
			if(in_transferlist)
			{
				$html.append("<div class='msgbuttons'>"+make_button(global_content["ok"],"javascript:modal.hide()","")+"</div>");
			}
			else
			{
				$html.append("<div class='msgbuttons'>"+make_button(global_content["ok"],"javascript:page_refresh()","")+"</div>");
				body_refresh();
			}
			modal.html($html).banner();
		}
	},"json");
}
// Player notes
function player_note(player_id)
{
	modal.html("<div class='std align_center'>"+get_loading_img()+"</div>").show();
	$.post("/ajax/players_note.ajax.php",{"type":"get_note","player_id":player_id},function(data){
		if(data != null)
		{
			var $html = $("<div>");
			$html.append("<h2>"+global_content[449]+"</h2>");
			if(data["text"] != "")
			{
				$html.append("<p class='dark rounded' style='padding: 10px;'><span class='subtle'>"+global_content[450]+"</span> "+data["note"]+"</p>");
			}
			$html.append("<form><label for='player_note'>"+global_content[451]+"</label><br /><textarea rows='7' cols='70' class='emboss' id='player_note'>"+data["text"]+"</textarea><div class='msgbuttons'>"+make_button("<img src='/pics/icons/clips2.gif' style='position:relative;top: 2px;'> "+global_content["save"],"save_player_note("+player_id+")","button big_button large button_icon primary_button")+" "+make_button(global_content["cancel"],"modal.hide();")+"</div>");
			modal.html($html);
			emboss();
		}
	},"json");
}
function save_player_note(player_id)
{
	var note = $("#player_note").val();
	modal.transition(get_loading_img(),function(){
		$.post("/ajax/players_note.ajax.php",{"type":"save_note","player_id":player_id,"note":note},function(data){
			if(data != null)
			{
				var $html = $("<div>");
				$html.append("<h2>"+global_content[449]+"</h2>");
				if(data["error"] == "")
				{
					$html.append("<p>"+global_content[452]+"</p>");
				}
				else
				{
					$html.append("<p>"+data["error"]+"</p>");
				}
				$html.append("<div class='msgbuttons'>"+make_button(global_content["ok"],"javascript:page_refresh()","")+"</div>");
				body_refresh();
				modal.html($html).banner();
			}
		},"json");
	});
}
function zeros(val,digits){
	val = ""+val;
	var length = val.length;
	if(length < digits)
	{
		for(var i=length; i <digits;i++)
		{
			val = "0"+val;
		}
	}
	return val;
}
function chars_left(chars_id,max_chars,input_id)
{
	var $chars = $("#"+chars_id);
	var $input = $("#"+input_id);
	if($input.val().length > max_chars)
	{
		var val = $input.val().substr(0,max_chars);
		$input.val(val);
	}
	chars = max_chars - $input.val().length;
	$chars.html(chars);
}
function jqclublink(ar)
{
	ar = ar || {};
	var wrap = $("<span />");
	var link = $("<a />").attr("href","/club/"+ar["id"]+"/").appendTo(wrap);
	if(ar["auto_tooltip"]) activate_club_links(link.attr("club_link",ar["id"]+""));
	if(ar["class"]) link.addClass(ar["class"]);
	if(ar["tooltip"]) link.tooltip(ar["tooltip"]);
	if(ar["name"]) link.html(ar["name"]);
	if(ar["html"]) link.append(ar["html"]);
	if(ar["flag"] && ar["country"]) wrap.append($("<span/>").text(" "),jqcountrylink({"country":ar["country"]}));
	if(ar["attr"])
	{
		for(var i in ar["attr"])
		{
			if(ar["attr"][i]) link.attr(i,ar["attr"][i]);
		}
	}
	if(ar["get_text"]) return $("<div />").html(wrap).html();
	return wrap;
}
function jqcountrylink(ar)
{
	if(!ar["country"]) 
	{
		if(ar["get_text"]) return "";
		return [];
	}
	var link = $("<a />").attr("href","/national-teams/"+ar["country"]+"/");
	if(ar["name"]) link.append(ar["name"]+" ");
	if(!ar["no_flag"]) link.append(get_flag(ar["country"]));
	if(ar["get_text"]) return $("<div />").html(link).html();
	return link;
}
function jqplayerlink(ar)
{
	ar = ar || {};
	var wrap = $("<span />");
	var link = $("<a />").attr("href","/players/"+ar["id"]+"/").appendTo(wrap);
	if(ar["name"]) link.append(ar["name"]);
	if(ar["flag"] && ar["country"]) wrap.append($("<span/>").text(" "),jqcountrylink({"country":ar["country"]}));
	if(ar["class"]) link.addClass(ar["class"]);
	if(ar["tooltip"]) link.tooltip(ar["tooltip"]);
	if(ar["auto_tooltip"]) activate_player_links(link.attr("player_link",ar["id"]+""));
	if(ar["attr"])
	{
		for(var i in ar["attr"])
		{
			if(ar["attr"][i]) link.attr(i,ar["attr"][i]);
		}
	}
	if(ar["get_text"]) return $("<div />").html(wrap).html();
	return wrap;
}
function jqclublogo(ar)
{
	if(ar["default"])
	{
		var logo_id = (ar["id"]%25+1)+"";
		if(logo_id.length==1) logo_id="0"+logo_id;
		var url = "/pics/logos_nonpro/"+logo_id;
	}
	else 	var url = "/pics/club_logos/"+ar["id"];
	if(ar["size"]=="small") url+="_25";
	else if(ar["size"]=="large") url+="_140";
	url+=".png";
	if(ar["md5"]) url+="?img="+ar["md5"];
	var img = $("<img />").attr("src",url).addClass("club_logo");
	if(ar["class"]) img.addClass(ar["class"]);
	if(ar["attr"])
	{
		for(var i in ar["attr"])
		{
			if(ar["attr"][i]) img.attr(i,ar["attr"][i]);
		}
	}
	return img;
}
